/*
 * @Descripttion:
 * @Author: voanit
 * @Date: 2022-05-08 17:09:43
 * @LastEditors: voanit
 * @LastEditTime: 2022-05-09 08:29:57
 */
import React, { useState } from 'react'
// console.log(useState, 77)
const State = () => {
  // count==变量名接收初始值：10， setCount：修改这个count的函数  传入修改的数据
  const [count, setCount] = useState(() => {
    console.log(123)
    return 10
  })
  const [val, setVal] = useState(() => {
    return 12
  })
  // console.log(count, 9)
  const handle = (e) => {
    // console.log(e.target.value, 99)
    // setVal(e.target.value)
    // setVal(() => {
    //   return val + 2
    // })
    // setVal(() => {
    //   return val + 2
    // })
    // setVal(() => {
    //   return val + 2
    // })
    // console.log(val)
    // setVal(val + 2)
    // setVal(val + 2)
    // console.log(val, 888)
    // setVal((msg) => {
    //   // 上一次的值
    //   console.log(msg, 777)
    //   console.log(val, 888)
    //   return val + 2
    // })
  }
  const handle2 = () => {
    console.log(22)
    // setCount(count + 1)
    // setCount(count + 2)
    // setCount(count + 3)
  }

  return (
    <div>
      御剑乘风来,除魔天地间!=-=State===={count}==
      <button onClick={() => setCount(count + 1)}>+1</button>
      <button onClick={() => handle2()}>+999</button>
      <hr />
      <input value={val} onChange={handle} />
      ==={val}
    </div>
  )
}
export default State
